package infostroy.bookagolf.components.inputs;

import infostroy.bookagolf.common.Constants.Colors;

import javax.swing.*;
import java.awt.*;
import java.awt.geom.RoundRectangle2D;

public class GolfTextArea extends JTextArea implements Colors{

    private Shape shape;

    public GolfTextArea() {
        this.setLineWrap(true);
        this.setWrapStyleWord(true);
        this.setOpaque(false);
        this.setMargin(new Insets(5, 5, 5, 5));
    }

    @Override
    protected void paintComponent(Graphics g) {
        Graphics2D graphics = (Graphics2D) g;
        graphics.setColor(PANEL_BACKGROUND);
        graphics.fill(new Rectangle(0, 0, this.getWidth(), this.getHeight()));
        graphics.setColor(Color.white);
        graphics.fillRoundRect(0, 0, this.getWidth() - 1, this.getHeight() - 1, 10, 10);

        GradientPaint gradient = new GradientPaint(0, 0, TEXT_SHADOW_START, 0, 5, TEXT_SHADOW_END);
        graphics.setPaint(gradient);
        graphics.fill(new Rectangle(0, 0, this.getWidth(), 5));
        super.paintComponent(g);
    }

    @Override
    protected void paintBorder(Graphics g) {
        g.setColor(INPUT_BORDER);
        g.drawRoundRect(0, 0, this.getWidth() - 1, this.getHeight() - 1, 10, 10);
        g.dispose();
    }

    @Override
    public boolean contains(int x, int y) {
        if (shape == null || !shape.getBounds().equals(getBounds())) {
            shape = new RoundRectangle2D.Float(0, 0, getWidth() - 1, getHeight() - 1, 10, 10);
        }
        return shape.contains(x, y);
    }

    @Override
    public Dimension getMaximumSize() {
        return new Dimension(super.getMaximumSize().width, 100);
    }
}
